package com.hospital.demo.service.impl.gaoyuran;

import com.hospital.demo.enums.ExceptionCodeEnums;
import com.hospital.demo.exception.HospitalException;
import com.hospital.demo.mapper.gaoyuran.ApplicationMapper;
import com.hospital.demo.model.gaoyuran.Application;
import com.hospital.demo.service.gaoyuran.ApplicationSer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApplicationImpl implements ApplicationSer {


    @Autowired
    private ApplicationMapper applicationMapper;



    //双条件查询
    @Override
    public List<Application> selectAppByD(Application application) {
        return applicationMapper.selectAppByD(application);
    }

    //通过id查看申请表信息
    @Override
    public List<Application> findApplicationById(Integer aid) {
        return applicationMapper.selectByPrimaryKey(aid);
    }

    //查看所有申请表信息
    @Override
    public List<Application> findAllapplications() {
        return applicationMapper.findAllApplication();
    }
    //查看所有申请表信息
    @Override
    public List<Application> findAllapplicationsno() {
        return applicationMapper.findAllApplicationno();
    }
    //查看所有申请表信息
    @Override
    public List<Application> findAllapplicationsyes() {
        return applicationMapper.findAllApplicationyes();
    }

    //审批申请表信息
    @Override
    public int upDateApplication(Application application) {
        try {
            applicationMapper.updateByPrimaryKey(application);
        } catch (Exception e) {
            throw new HospitalException(ExceptionCodeEnums.UPDATE_FAIL);
        }
        return 0;
    }

    //提交申请表信息
    @Override
    public int AddApplication(Application application) {
        try {
            applicationMapper.insert(application);
        } catch (Exception e) {
            throw new HospitalException(ExceptionCodeEnums.INSERT_FAIL);
        }
        return 0;
    }
}
